package com.huzz.controller;

import com.huzz.entity.SysDictItem;
import com.huzz.model.SysDictItemCreateModel;
import com.huzz.model.SysDictItemQueryModel;
import com.huzz.model.SysDictItemUpdateModel;
import com.huzz.service.ISysDictItemService;
import com.huzz.util.body.JsonResult;
import com.huzz.util.body.ResultTool;
import com.huzz.util.log.Log;
import com.huzz.util.log.LogStarter;
import com.huzz.util.log.Operate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* 系统字典Item-业务模块
*
* @author 童年的纸飞机
* @since 2023-06-07 13:27
*/
@Slf4j
@LogStarter("系统字典Item模块")
@RestController
@RequestMapping("/api/SysDictItem")
@Api(value = "系统字典Item模块 API", tags = {"系统字典Item API"})
public class SysDictItemController {

    @Autowired
    private ISysDictItemService sysDictItemService;

    @Log(name = "根据id查询系统字典Item", operateType = Operate.SELECT)
    @ApiOperation("根据id查询系统字典Item")
    @GetMapping("/findSysDictItemById")
    public JsonResult<SysDictItem> findSysDictItemById(@RequestParam Integer id) {
        return ResultTool.success(sysDictItemService.getSysDictItemById(id));
    }

    @Log(name = "新建系统字典Item", operateType = Operate.INSERT)
    @ApiOperation("新建系统字典Item")
    @PostMapping("/createSysDictItem")
    public JsonResult createSysDictItem(@Validated @RequestBody SysDictItemCreateModel model) {
        return sysDictItemService.createSysDictItem(model) ? ResultTool.success("新建成功") : ResultTool.fail("新建失败");
    }

    @Log(name = "更新系统字典Item", operateType = Operate.UPDATE)
    @ApiOperation("更新系统字典Item")
    @PutMapping("/updateSysDictItem")
    public JsonResult updateSysDictItem(@Validated @RequestBody SysDictItemUpdateModel model) {
        return sysDictItemService.updateSysDictItem(model) ? ResultTool.success("更新成功") : ResultTool.fail("更新失败");
    }

    @Log(name = "根据ID删除系统字典Item", operateType = Operate.DELETE)
    @ApiOperation("根据ID删除系统字典Item")
    @DeleteMapping("/removeSysDictItemById")
    public JsonResult removeSysDictItemById(@RequestParam Integer id) {
        return sysDictItemService.deleteSysDictItemById(id) ? ResultTool.success("删除成功") : ResultTool.fail("删除失败");
    }

    @Log(name = "分页查询系统字典Item", operateType = Operate.SELECT)
    @ApiOperation("分页查询系统字典Item列表")
    @GetMapping("/querySysDictItemPage")
    public JsonResult querySysDictItemPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @Validated SysDictItemQueryModel model) {
        return ResultTool.success(sysDictItemService.selectSysDictItemPage(pageNum, pageSize, model));
    }

    @Log(name = "查询系统字典Item列表", operateType = Operate.SELECT)
    @ApiOperation("查询系统字典Item列表")
    @GetMapping("/querySysDictItemList")
    public JsonResult querySysDictItemList(@Validated SysDictItemQueryModel model) {
        return ResultTool.success(sysDictItemService.selectSysDictItemList(model));
    }

    @Log(name = "导出系统字典Item", operateType = Operate.EXPORT, saveResResult = false)
    @ApiOperation("导出系统字典Item列表")
    @GetMapping("/exportSysDictItemExcel")
    public void exportSysDictItemExcel(HttpServletRequest request, HttpServletResponse response, @Validated SysDictItemQueryModel model) {
        sysDictItemService.exportSysDictItemExcel(request, response, model);
    }

    @Log(name = "批量编辑系统字典Item", operateType = Operate.UPDATE)
    @ApiOperation("批量编辑系统字典Item")
    @PutMapping("/updateSysDictItemByList")
    public JsonResult updateSysDictItemByList(@RequestBody List<SysDictItemUpdateModel> modelList) {
        return ResultTool.response(sysDictItemService.updateSysDictItemByList(modelList));
    }

    @Log(name = "批量删除系统字典Item", operateType = Operate.DELETE)
    @ApiOperation("批量删除系统字典Item")
    @DeleteMapping("/removeSysDictItemByIds")
    public JsonResult removeSysDictItemByIds(@RequestBody List<Integer> ids) {
        return ResultTool.response(sysDictItemService.deleteSysDictItemByIds(ids));
    }

}

